<?php
/**
 * 保存操作
 * Enter description here ...
 * @author nijn
 *
 */
class EditAction extends CAction {

	/**
	 * 模型
	 * Enter description here ...
	 * @var unknown_type
	 */
	public $modelName = '';
	/**
	 * 成功提示语
	 * Enter description here ...
	 * @var unknown_type
	 */
	public $msg = '操作成功！';
	/**
	 * 成功跳转地址
	 * Enter description here ...
	 * @var unknown_type
	 */
	public $returnUrl;
	/**
	 * 页面
	 * Enter description here ...
	 * @var unknown_type
	 */
	public $view;
	
	public function run() {
		$c = $this->controller;
		$modelName = empty($this->modelName) ? $c->modelName : $this->modelName;
		$model = new $modelName();
		if (isset($_POST[$modelName])) {
			$model->attributes = $_POST[$modelName];
			if ($model->save()) {
				Yii::app()->user->setFlash(FLASH::RESULT_SUCCESS, $this->msg);
				$c->redirect($this->returnUrl);
			}
		}
		
		$c->render($this->view, array(
			'model' => $model,
		));
	}
}

?>